package com.github.dapeng.soa.scala

import com.github.dapeng.soa.scala.info.serializer._;

        import com.github.dapeng.core._
        import com.github.dapeng.org.apache.thrift._
        import com.github.dapeng.org.apache.thrift.protocol._
        import com.github.dapeng.core.definition._

        import scala.concurrent.ExecutionContext.Implicits.global
        import java.util.concurrent.{CompletableFuture, Future}
        import scala.compat.java8.FutureConverters._

        /**
        * Autogenerated by Dapeng-Code-Generator (1.2.2)
        *
        * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
        *  @generated
        **/
        object CalculateServiceAsyncCodec {

        
            case class calcualteWordCount_args(filename:String,word:String)

            case class calcualteWordCount_result(success:Int)

            class CalcualteWordCount_argsSerializer extends BeanSerializer[calcualteWordCount_args]{
            
      @throws[TException]
      override def read(iprot: TProtocol): calcualteWordCount_args = {

        var schemeField: com.github.dapeng.org.apache.thrift.protocol.TField = null
        iprot.readStructBegin()

      var filename: String = null
        var word: String = null
        

      while (schemeField == null || schemeField.`type` != com.github.dapeng.org.apache.thrift.protocol.TType.STOP) {

        schemeField = iprot.readFieldBegin

        schemeField.id match {
          
              case 1 =>
                  schemeField.`type` match {
                    case com.github.dapeng.org.apache.thrift.protocol.TType.STRING => filename = iprot.readString
                    case _ => com.github.dapeng.org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.`type`)
            }
            
              case 2 =>
                  schemeField.`type` match {
                    case com.github.dapeng.org.apache.thrift.protocol.TType.STRING => word = iprot.readString
                    case _ => com.github.dapeng.org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.`type`)
            }
            
          case _ => com.github.dapeng.org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.`type`)
        }
      }

      iprot.readFieldEnd
      iprot.readStructEnd

      val bean = calcualteWordCount_args(filename = filename,word = word)
      validate(bean)

      bean
      }
    
      @throws[TException]
      override def write(bean: calcualteWordCount_args, oprot: TProtocol): Unit = {

      validate(bean)
      oprot.writeStructBegin(new com.github.dapeng.org.apache.thrift.protocol.TStruct("calcualteWordCount_args"))

      
            {
            val elem0 = bean.filename 
            oprot.writeFieldBegin(new com.github.dapeng.org.apache.thrift.protocol.TField("filename", com.github.dapeng.org.apache.thrift.protocol.TType.STRING, 1.asInstanceOf[Short]))
            oprot.writeString(elem0)
            oprot.writeFieldEnd
            
            }
            {
            val elem1 = bean.word 
            oprot.writeFieldBegin(new com.github.dapeng.org.apache.thrift.protocol.TField("word", com.github.dapeng.org.apache.thrift.protocol.TType.STRING, 2.asInstanceOf[Short]))
            oprot.writeString(elem1)
            oprot.writeFieldEnd
            
            }
      oprot.writeFieldStop
      oprot.writeStructEnd
    }
    
      @throws[TException]
      override def validate(bean: calcualteWordCount_args): Unit = {
      
              if(bean.filename == null)
              throw new SoaException(SoaBaseCode.NotNull, "filename字段不允许为空")
            
              if(bean.word == null)
              throw new SoaException(SoaBaseCode.NotNull, "word字段不允许为空")
            
    }
    

            override def toString(bean: calcualteWordCount_args): String = if(bean == null)  "null" else bean.toString
          }

            class CalcualteWordCount_resultSerializer extends BeanSerializer[calcualteWordCount_result]{

            @throws[TException]
            override def read(iprot: TProtocol): calcualteWordCount_result = {

              var schemeField: com.github.dapeng.org.apache.thrift.protocol.TField = null
              iprot.readStructBegin

              var success : Int = 0

              while (schemeField == null || schemeField.`type` != com.github.dapeng.org.apache.thrift.protocol.TType.STOP) {

                schemeField = iprot.readFieldBegin

                schemeField.id match {
                  case 0 =>
                  schemeField.`type` match {
                    case com.github.dapeng.org.apache.thrift.protocol.TType.I32 =>  success = iprot.readI32
                    case _ => com.github.dapeng.org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.`type`)
                  }
                  case _ => com.github.dapeng.org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.`type`)
                }

                iprot.readFieldEnd
              }

              iprot.readStructEnd
              val bean = calcualteWordCount_result(success)
              validate(bean)

              bean
            }

            
      @throws[TException]
      override def write(bean: calcualteWordCount_result, oprot: TProtocol): Unit = {

      validate(bean)
      oprot.writeStructBegin(new com.github.dapeng.org.apache.thrift.protocol.TStruct("calcualteWordCount_result"))

      
            {
            val elem0 = bean.success 
            oprot.writeFieldBegin(new com.github.dapeng.org.apache.thrift.protocol.TField("success", com.github.dapeng.org.apache.thrift.protocol.TType.I32, 0.asInstanceOf[Short]))
            oprot.writeI32(elem0)
            oprot.writeFieldEnd
            
            }
      oprot.writeFieldStop
      oprot.writeStructEnd
    }
    
            
      @throws[TException]
      override def validate(bean: calcualteWordCount_result): Unit = {
      
    }
    

            override def toString(bean: calcualteWordCount_result): String = if(bean == null)  "null" else bean.toString
          }

            class calcualteWordCount extends SoaFunctionDefinition.Async[com.github.dapeng.soa.scala.service.CalculateServiceAsync, calcualteWordCount_args, calcualteWordCount_result]("calcualteWordCount", new CalcualteWordCount_argsSerializer(), new CalcualteWordCount_resultSerializer()){

            @throws[TException]
            def apply(iface: com.github.dapeng.soa.scala.service.CalculateServiceAsync, args: calcualteWordCount_args):Future[calcualteWordCount_result] = {

              val _result = iface.calcualteWordCount(args.filename,args.word,50000).asInstanceOf[CompletableFuture[Int]]
              _result.thenApply(calcualteWordCount_result(_))

            }
          }
          
            case class calcualteWordsCount_args(fileName:String)

            case class calcualteWordsCount_result(success:Map[String, Int])

            class CalcualteWordsCount_argsSerializer extends BeanSerializer[calcualteWordsCount_args]{
            
      @throws[TException]
      override def read(iprot: TProtocol): calcualteWordsCount_args = {

        var schemeField: com.github.dapeng.org.apache.thrift.protocol.TField = null
        iprot.readStructBegin()

      var fileName: String = null
        

      while (schemeField == null || schemeField.`type` != com.github.dapeng.org.apache.thrift.protocol.TType.STOP) {

        schemeField = iprot.readFieldBegin

        schemeField.id match {
          
              case 1 =>
                  schemeField.`type` match {
                    case com.github.dapeng.org.apache.thrift.protocol.TType.STRING => fileName = iprot.readString
                    case _ => com.github.dapeng.org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.`type`)
            }
            
          case _ => com.github.dapeng.org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.`type`)
        }
      }

      iprot.readFieldEnd
      iprot.readStructEnd

      val bean = calcualteWordsCount_args(fileName = fileName)
      validate(bean)

      bean
      }
    
      @throws[TException]
      override def write(bean: calcualteWordsCount_args, oprot: TProtocol): Unit = {

      validate(bean)
      oprot.writeStructBegin(new com.github.dapeng.org.apache.thrift.protocol.TStruct("calcualteWordsCount_args"))

      
            {
            val elem0 = bean.fileName 
            oprot.writeFieldBegin(new com.github.dapeng.org.apache.thrift.protocol.TField("fileName", com.github.dapeng.org.apache.thrift.protocol.TType.STRING, 1.asInstanceOf[Short]))
            oprot.writeString(elem0)
            oprot.writeFieldEnd
            
            }
      oprot.writeFieldStop
      oprot.writeStructEnd
    }
    
      @throws[TException]
      override def validate(bean: calcualteWordsCount_args): Unit = {
      
              if(bean.fileName == null)
              throw new SoaException(SoaBaseCode.NotNull, "fileName字段不允许为空")
            
    }
    

            override def toString(bean: calcualteWordsCount_args): String = if(bean == null)  "null" else bean.toString
          }

            class CalcualteWordsCount_resultSerializer extends BeanSerializer[calcualteWordsCount_result]{

            @throws[TException]
            override def read(iprot: TProtocol): calcualteWordsCount_result = {

              var schemeField: com.github.dapeng.org.apache.thrift.protocol.TField = null
              iprot.readStructBegin

              var success : Map[String, Int] = Map.empty

              while (schemeField == null || schemeField.`type` != com.github.dapeng.org.apache.thrift.protocol.TType.STOP) {

                schemeField = iprot.readFieldBegin

                schemeField.id match {
                  case 0 =>
                  schemeField.`type` match {
                    case com.github.dapeng.org.apache.thrift.protocol.TType.MAP =>  success = {
        val _map0 : com.github.dapeng.org.apache.thrift.protocol.TMap = iprot.readMapBegin
        val _result0 = (0 until _map0.size).map(_ => {( iprot.readString -> iprot.readI32 )}).toMap
        iprot.readMapEnd
        _result0
      }
                    case _ => com.github.dapeng.org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.`type`)
                  }
                  case _ => com.github.dapeng.org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.`type`)
                }

                iprot.readFieldEnd
              }

              iprot.readStructEnd
              val bean = calcualteWordsCount_result(success)
              validate(bean)

              bean
            }

            
      @throws[TException]
      override def write(bean: calcualteWordsCount_result, oprot: TProtocol): Unit = {

      validate(bean)
      oprot.writeStructBegin(new com.github.dapeng.org.apache.thrift.protocol.TStruct("calcualteWordsCount_result"))

      
            {
            val elem0 = bean.success 
            oprot.writeFieldBegin(new com.github.dapeng.org.apache.thrift.protocol.TField("success", com.github.dapeng.org.apache.thrift.protocol.TType.MAP, 0.asInstanceOf[Short]))
            
        oprot.writeMapBegin(new com.github.dapeng.org.apache.thrift.protocol.TMap(com.github.dapeng.org.apache.thrift.protocol.TType.STRING, com.github.dapeng.org.apache.thrift.protocol.TType.I32, elem0.size))

        elem0.map{case(elem1, elem2) => {
          oprot.writeString(elem1)
          oprot.writeI32(elem2)
        }
        }
        oprot.writeMapEnd
      
            oprot.writeFieldEnd
            
            }
      oprot.writeFieldStop
      oprot.writeStructEnd
    }
    
            
      @throws[TException]
      override def validate(bean: calcualteWordsCount_result): Unit = {
      
              if(bean.success == null)
              throw new SoaException(SoaBaseCode.NotNull, "success字段不允许为空")
            
    }
    

            override def toString(bean: calcualteWordsCount_result): String = if(bean == null)  "null" else bean.toString
          }

            class calcualteWordsCount extends SoaFunctionDefinition.Async[com.github.dapeng.soa.scala.service.CalculateServiceAsync, calcualteWordsCount_args, calcualteWordsCount_result]("calcualteWordsCount", new CalcualteWordsCount_argsSerializer(), new CalcualteWordsCount_resultSerializer()){

            @throws[TException]
            def apply(iface: com.github.dapeng.soa.scala.service.CalculateServiceAsync, args: calcualteWordsCount_args):Future[calcualteWordsCount_result] = {

              val _result = iface.calcualteWordsCount(args.fileName,50000).asInstanceOf[CompletableFuture[Map[String, Int]]]
              _result.thenApply(calcualteWordsCount_result(_))

            }
          }
          

        case class getServiceMetadata_args()

        case class getServiceMetadata_result(success: String)

        class GetServiceMetadata_argsSerializer extends BeanSerializer[getServiceMetadata_args] {

          @throws[TException]
          override def read(iprot: TProtocol): getServiceMetadata_args = {

            iprot.readStructBegin

            var schemeField: com.github.dapeng.org.apache.thrift.protocol.TField = null

            while (schemeField == null || schemeField.`type` != com.github.dapeng.org.apache.thrift.protocol.TType.STOP) {
              schemeField = iprot.readFieldBegin
              com.github.dapeng.org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.`type`)
              iprot.readFieldEnd
            }

            iprot.readStructEnd

            val bean = getServiceMetadata_args()
            validate(bean)

            bean
          }

          @throws[TException]
          override def write(bean: getServiceMetadata_args, oproto: TProtocol): Unit = {
            validate(bean)
            oproto.writeStructBegin(new com.github.dapeng.org.apache.thrift.protocol.TStruct("getServiceMetadata_args"))

            oproto.writeFieldStop
            oproto.writeStructEnd
          }

          @throws[TException]
          override def validate(bean: getServiceMetadata_args): Unit = {}

          override def toString(bean: getServiceMetadata_args): String = if (bean == null) "null" else bean.toString
        }



        class GetServiceMetadata_resultSerializer extends BeanSerializer[getServiceMetadata_result] {
          @throws[TException]
          override def read(iprot: TProtocol): getServiceMetadata_result = {
            iprot.readStructBegin

            var schemeField: com.github.dapeng.org.apache.thrift.protocol.TField = null

            var success: String = null

            while (schemeField == null || schemeField.`type` != com.github.dapeng.org.apache.thrift.protocol.TType.STOP) {
              schemeField = iprot.readFieldBegin

              schemeField.id match {
                case 0 =>
                schemeField.`type` match {
                  case com.github.dapeng.org.apache.thrift.protocol.TType.STRING => success = iprot.readString
                  case _ => com.github.dapeng.org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.`type`)
                }
                case _ => com.github.dapeng.org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.`type`)
              }
              iprot.readFieldEnd
            }

            iprot.readStructEnd
            val bean = getServiceMetadata_result(success)
            validate(bean)

            bean
          }

          @throws[TException]
          override def write(bean: getServiceMetadata_result, oproto: TProtocol): Unit = {
            validate(bean)
            oproto.writeStructBegin(new com.github.dapeng.org.apache.thrift.protocol.TStruct("getServiceMetadata_result"))

            oproto.writeFieldBegin(new com.github.dapeng.org.apache.thrift.protocol.TField("success", com.github.dapeng.org.apache.thrift.protocol.TType.STRING, 0.asInstanceOf[Short]))
            oproto.writeString(bean.success)
            oproto.writeFieldEnd

            oproto.writeFieldStop
            oproto.writeStructEnd
          }

          @throws[TException]
          override def validate(bean: getServiceMetadata_result): Unit = {
            if (bean.success == null)
            throw new SoaException(SoaBaseCode.NotNull, "success字段不允许为空")
          }

          override def toString(bean: getServiceMetadata_result): String = if (bean == null) "null" else bean.toString

        }



        class getServiceMetadata extends SoaFunctionDefinition.Async[com.github.dapeng.soa.scala.service.CalculateServiceAsync, getServiceMetadata_args, getServiceMetadata_result](
        "getServiceMetadata", new GetServiceMetadata_argsSerializer(), new GetServiceMetadata_resultSerializer()) {


          @throws[TException]
          override def apply(iface: com.github.dapeng.soa.scala.service.CalculateServiceAsync, args: getServiceMetadata_args): Future[getServiceMetadata_result] = {

            val result = scala.concurrent.Future {
            val source = scala.io.Source.fromInputStream(CalculateServiceCodec.getClass.getClassLoader.getResourceAsStream("com.lbb.hello.service.HelloService.xml"))
            val success = source.mkString
            source.close
            getServiceMetadata_result(success)
            }
            result.toJava.toCompletableFuture

          }
        }

        class Processor(iface: com.github.dapeng.soa.scala.service.CalculateServiceAsync) extends
        SoaServiceDefinition(iface,classOf[com.github.dapeng.soa.scala.service.CalculateServiceAsync], Processor.buildMap)

        object Processor{

          type PF = SoaFunctionDefinition[com.github.dapeng.soa.scala.service.CalculateServiceAsync, _, _]

          def buildMap(): java.util.Map[String, PF] = {
            val map = new java.util.HashMap[String, PF]()
            map.put("calcualteWordCount", new calcualteWordCount)
              map.put("calcualteWordsCount", new calcualteWordsCount)
              
            map.put("getServiceMetadata", new getServiceMetadata)
            map
          }

        }
      }
      